/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package assignemnt1;

/**
 *
 * @author Hansel-G
 */
public class MainUI {
 ProjModel pm;
 GridView gv = new GridView();
 int count = 0;

    public MainUI() {
        pm = new ProjModel();
    }

    public void showMenu() {
        /*
        === MENU ===
        1. Set Number of horizontal lanes (H-street) [min 1, max 3]
        2. Set Number of vertical lanes  (V-street) [min 1, max 4]
        3. Set Probability of a car entering H-street [min 0, max 1]
        3. Set Probability of a car entering V-street [min 0, max 1]
        5. Run one simulation cycle
        6. Set and run number of simulation cycles [min 1, max 10]
        Enter your choice>           */
        System.out.print( " === MENU ===\n" +
                " 1. Set Number of horizontal lanes (H-street) [min 1, max 3]\n" +
                " 2. Set Number of vertical lanes  (V-street) [min 1, max 4]\n" +
                " 3. Set Probability of a car entering H-street [min 0, max 1]\n" +
                " 4. Set Probability of a car entering V-street [min 0, max 1]\n" +
                " 5. Run one simulation cycle\n" +
                " 6. Set and run number of simulation cycles [min 1, max 10]\n" +
                " ");
        String userChoice = GetUserInput.getUserChoice("Enter your choice>");
        int userChoiceInt = Integer.parseInt(userChoice);
        System.out.println("After int conversion" + userChoiceInt);

        switch(userChoiceInt) {
            case 1 : System.out.println("Menu 1");
                     setNumHorLanes();
                     showMenu();
                break;
            case 2 : System.out.println("Menu 2");
                     setNumVerLanes();
                     showMenu();
                break;
            case 3 : System.out.println("Menu 3");
                     setHorProb();
                     showMenu();
                break;
            case 4 : System.out.println("Menu 4");
            setVerProb();
            showMenu();
                break;
            case 5 : System.out.println("Menu 5");
                showRoad();
                showMenu();
                break;
            case 6 : System.out.println("Menu 6");
            showRoad();
            showMenu();
                break;
            default : System.out.println("Error in entering menu choice");
                break;
        }

      }

    public void setHorProb () {
        String userChoice = GetUserInput.getUserChoice("Enter number of probability car entering horiz lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 0;
        int upperLimit = 1;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
           System.out.println("Error in entering horiz probability");
           System.out.println("Please enter number above 0 and below 1. ");
           showMenu();
        } else {
            pm.setHorProb(userChoiceInt);

        }

    }
    public void setVerProb () {
        String userChoice = GetUserInput.getUserChoice("Enter number of probability car entering vertical lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 0;
        int upperLimit = 1;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
           System.out.println("Error in entering vertical probability");
           System.out.println("Please enter number above 0 and below 1. ");
           showMenu();
        } else {
            pm.setVerProb(userChoiceInt);

        }

    }


    public void setNumHorLanes () {
        String userChoice = GetUserInput.getUserChoice("Enter number of horiz lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 1;
        int upperLimit = 3;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
           System.out.println("Error in entering horiz lanes");
           System.out.println("Please enter number above 1 and below 3. ");
           showMenu();
        } else {
            pm.setHorLanes(userChoiceInt);
            
        }

    }
    public void showRoad(){

        char[][] cell = gv.gridViewSetup(pm.getHorLanes(),pm.getVerLanes());
        gv.buildHorCars(cell, count);
        gv.buildVerCars(cell, count);
        int HGrid = 25;
        int VGrid = 26;
        for (int i = 0; i < HGrid ; i++){
            for (int j = 0; j<VGrid; j++)
            System.out.print(cell[i][j]);
                            System.out.println();
        }
        count++;
    }
    public void setNumVerLanes () {
        String userChoice = GetUserInput.getUserChoice("Enter number of vert lanes : ");
        int userChoiceInt = Integer.parseInt(userChoice);
        int lowerLimit = 1;
        int upperLimit = 4;
        if (userChoiceInt > upperLimit || userChoiceInt < lowerLimit) {
           System.out.println("Error in entering horiz lanes");
           System.out.println("Please enter number above 1 and below 3. ");
           showMenu();
        } else { 
            pm.setVerLanes(userChoiceInt);
            
        }

    }
    public int showHorLanes() {
        return pm.getHorLanes();
    }

    public int showVerLanes() {
        return pm.getVerLanes();
    }


}

